$(function () {
    $("#jqGrid").jqGrid({
        url: '../empmsgsend/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '员工编号', name: 'empNo', index: 'emp_no', width: 80 }, 			
			{ label: '姓名', name: 'empName', index: 'emp_name', width: 80 }, 			
			{ label: '部门', name: 'department', index: 'department', width: 80 }, 			
			{ label: '部门名称', name: 'departmentName', index: 'department_name', width: 80 }, 			
			{ label: '主题', name: 'title', index: 'title', width: 80 }, 			
			{ label: '内容', name: 'content', index: 'content', width: 80 }, 			
			{ label: '接收人id,逗号隔开', name: 'receiver', index: 'receiver', width: 80 }, 			
			{ label: '上传文件路径', name: 'uploadFilePath', index: 'upload_file_path', width: 80 }, 			
			{ label: '创建时间', name: 'createDate', index: 'create_date', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

   // var r2 = getListinfo2();
   // vm.emps = r2;
});

// $(window).on('load', function () {
//     $('#usertype').selectpicker({
//         'selectedText': 'cat'
//     });
// });

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		empMsgSend: {},
		emps:{}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
            vm.showList = false;
			vm.title = "新增";
			vm.empMsgSend = {
                empName:"",
                receivers:[]
			};
			// vm.emps = [];[{"id":6,"name":"王大江"},{"id":7,"name":"李志伟"}]

            // alert(JSON.stringify(vm.emps))
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id);
		},
		saveOrUpdate: function (event) {
            vm.empMsgSend.createDate = $("#createDate").val();
			var url = vm.empMsgSend.id == null ? "../empmsgsend/save" : "../empmsgsend/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.empMsgSend),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../empmsgsend/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../empmsgsend/info/"+id, function(r){
                vm.empMsgSend = r.empMsgSend;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		},
        popPage: function(){
            utils.popGrid();
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择员工",
                area: ['800px', '450px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#popLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var grid = $("#popGrid");
                    var rowKey = grid.getGridParam("selrow");
                    if(!rowKey){
                        alert("请选择一条记录");
                        return ;
                    }
                    var rowData=grid.jqGrid("getRowData",rowKey);
                    vm.empMsgSend.empName = rowData.name;
                    vm.empMsgSend.empNo = rowData.id;
                    vm.empMsgSend.departmentName = rowData.department;

                    layer.close(index);
                }
            });
        },
        getListinfo: function(){
            $.get("../empmsgsend/getListinfo", function(r){
                vm.emps =r.emps;
                // vm.emps = [];
                // vm.emps[0] = r.emps[0];
                // vm.emps = r.emps;
                // console.log(vm.emps);
            });


        }


	}
});


getListinfo2 = function(){
var r2 = null;
    $.ajax({
        type: "POST",
        url: "../empmsgsend/getListinfo",
        contentType: "application/json",
        // data: JSON.stringify(params),
        dataType:"json",
        async:false,
        cache:false,
        success: function(r){
            r2 = r;
        }

    });

  return r2;

}